<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:str="http://exslt.org/strings"
    xmlns:exsl="http://exslt.org/common"
    xmlns:ep="urn:ep"
    extension-element-prefixes="str exsl">

    <xsl:import href="ep_render_component_parts.xsl" />

    <!-- ***************** render_component ******************* -->
    <xsl:template name="render_component">
        <xsl:param name="component" />
        <xsl:param name="prev_component" />
        <xsl:param name="target" />
        <xsl:param name="query" />
        <xsl:param name="message" />
        <xsl:param name="epc_size_state" />
        <xsl:param name="minimize" select="0" />    <!-- param to force minimized view (overrides the param below!) -->
        <xsl:param name="maximize" select="0" />    <!-- param to force "maximized" (shown) view -->
        <xsl:param name="epc_input" />              <!-- param to take in the output of the previous component -->
        <xsl:param name="user_level" />

        <!-- decide whether to display component (or to show it "minimized") on the basis of the presence 
             of @display in the query (0 or 1). If not present, take the @display value from the component
             definition file -->
        <xsl:variable name="display_component">
            <xsl:choose>
                <xsl:when test="$minimize=1"><xsl:value-of select="0"/></xsl:when>
                <xsl:when test="$maximize=1"><xsl:value-of select="1"/></xsl:when>
                <xsl:when test="($query/@display=1) or ($query/@display=0)"><xsl:value-of select="$query/@display"/></xsl:when>
                <xsl:when test="($component/@display=1) or ($component/@display=0)"><xsl:value-of select="$component/@display"/></xsl:when>
                <xsl:otherwise><xsl:value-of select="1"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <!-- start component -->
        <input type="hidden" name="component" value="{$component/@id}" />

        <!-- context help -->
        <xsl:call-template name="context_help"><xsl:with-param name="ctxt_helps" select="$component//context_help" /></xsl:call-template>

        <!-- display_component: 0 - hide, 1 - show -->
        <input type="hidden" name="display_component_{$component/@id}" value="{$display_component}" />

        <!-- component always has itself as the first (sometimes only!) target -->
        <input type="hidden" id="ep_targets___c_{$component/@id}" name="targets___c_{$component/@id}" value="{$component/@id}" />
        <input type="hidden" name="epc_size_state" value="{$epc_size_state}" />

        <!-- title bar title: show special for basic container output -->
        <xsl:variable name="title_bar_title">
            <xsl:if test="$component/@id!=-1"><xsl:value-of select="$component/@title" /></xsl:if>
            <xsl:if test="$component/@id=-1"><xsl:value-of select="$prev_component/@title" /> Output</xsl:if>
        </xsl:variable>

        <!-- title bar (always shown) - makes the "minimized" state -->
        <xsl:call-template name="component_title_bar">
            <xsl:with-param name="title" select="$title_bar_title" />
            <xsl:with-param name="id" select="$component/@id" />
            <xsl:with-param name="error_message" select="$message" />
            <xsl:with-param name="about" select="$component/about" />
            <xsl:with-param name="epc_size_state" select="$epc_size_state" />
        </xsl:call-template>

        <!-- the main body of the component (include inside the component table) -->
        <xsl:if test="$display_component=1">
            <div class="ep_component_body">
                <xsl:apply-templates select="$component/section">
                    <xsl:with-param name="query" select="$query" />
                    <xsl:with-param name="target" select="$target" />
                    <xsl:with-param name="display_component" select="$display_component" />
                    <xsl:with-param name="epc_input" select="$epc_input" />
                    <xsl:with-param name="process_status" select="$message" />
                </xsl:apply-templates>
            </div>
        </xsl:if>

        <!-- if we minimize the component, still should put up as "hidden" all the input fields,
             to keep passing the information; pass the $display_component variable to indicate this -->
        <xsl:if test="$display_component=0">
            <xsl:apply-templates select="$component/section">
                <xsl:with-param name="query" select="$query"/>
                <xsl:with-param name="target" select="$target"/>
                <xsl:with-param name="display_component" select="$display_component"/>
                <xsl:with-param name="epc_input" select="$epc_input"/>
            </xsl:apply-templates>
        </xsl:if>
    </xsl:template>

  <!-- ***************** section  ******************* -->
    <xsl:template match="section">
        <xsl:param name="query" />
        <xsl:param name="target" />
        <xsl:param name="display_component" />
        <xsl:param name="process_status" />
	<xsl:param name="epc_input" />

        <xsl:variable name="this_sec_id" select="./@id" />

        <xsl:variable name="target_activated_subsection_id">
            <xsl:if test="$target">
                <xsl:if test="$target/activate_subsection[@section_id=$this_sec_id]">
                    <xsl:value-of select="$target/activate_subsection[@section_id=$this_sec_id]/@subsection_id" />
                </xsl:if>
            </xsl:if>
        </xsl:variable>

        <xsl:variable name="active_subsec_id">
            <xsl:choose>
                <xsl:when test="string-length($target_activated_subsection_id)&gt;0"><xsl:value-of select="$target_activated_subsection_id"/></xsl:when>
                <xsl:when test="count($query/section[@id=$this_sec_id]/subsection) &gt; 0"><xsl:value-of select="$query/section[@id=$this_sec_id]/@active_subsection_id"/></xsl:when>
                <xsl:when test="@default_active_subsec"><xsl:value-of select="@default_active_subsec"/></xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <input type="hidden" name="section___c_{parent::component/@id}" value="{@id}" />
        <input type="hidden" name="active_subsection_id___c_{parent::component/@id}_s_{@id}" value="{$active_subsec_id}" />
        <xsl:if test="$display_component=1">
            <div class="ep_section">
                <fieldset>
                    <xsl:if test="string-length(@title)&gt;0">
                        <xsl:attribute name="class">with_legend</xsl:attribute>
                        <legend><xsl:value-of select="@title" /></legend>
                    </xsl:if>
<!-- to do...
                <xsl:if test="./context_help">
                    <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation();</xsl:attribute>
                    <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
                </xsl:if>
-->
                    <xsl:if test="ancestor::component/@id != -1"><!-- -1 stands for basic container component, not sure why it's excluded if it's empty anyways (kolais) -->
<!-- to do...
                    <xsl:choose>
                        <xsl:when test="$user_level=0">
                            <legend><xsl:value-of select="@title" /></legend>
                            <xsl:if test="@help_id">
                                <a href="#"><img onclick="epc_help('/static/help/{//component[position()=1]/@help}#{@help_id}'); return false;" height="16" title="Help" src="{$html_href}/static/images/gui_icons/help.png"/></a>
                            </xsl:if>
                        </xsl:when>
                        <xsl:when test="$user_level=1">
                            <legend><xsl:value-of select="@title" /></legend>
                            <xsl:if test="@help_id">
                                <img onclick="epc_help('/static/help/{//component[position()=1]/@help}#{@help_id}')" height="16" title="Help" src="{$html_href}/static/images/gui_icons/help.png"/>
                            </xsl:if>
                        </xsl:when>
                    </xsl:choose>
-->
                    </xsl:if>
                    <div class="ep_section_body">
<!-- to do...
                <xsl:if test="@advanced=1 and $user_level=0">
                    <script type="text/javascript">
                        function toggle_adv_section___c_<xsl:value-of select="parent::component/@id"/>_<xsl:value-of select="@id"/>_vis ( obj )
                            {
                            var tobj = document.getElementById('adv_section___c_<xsl:value-of select="parent::component/@id"/>_<xsl:value-of select="@id"/>');
                            if ( tobj.style.display == 'none' )
                                {
                                tobj.style.display = '';
                                obj.innerHTML = 'collapse &lt;&lt;&lt;';
                                }
                            else
                                {
                                tobj.style.display = 'none';
                                obj.innerHTML = 'expand &gt;&gt;';
                                }
                            }
                    </script>
                    <span
                        style="border:thin outset; padding: 2px"
                        onmouseout="this.style.backgroundColor=''"
                        onmouseover="this.style.backgroundColor='lightblue';this.style.cursor='pointer'"
                        onclick="toggle_adv_section___c_{parent::component/@id}_{@id}_vis(this)">expand >>
                    </span>
                </xsl:if>
                <xsl:if test="@advanced=1 and $user_level=0">
                    <xsl:attribute name="style">display:none</xsl:attribute>
                </xsl:if>
-->
                        <xsl:if test="string-length(shorthelp)&gt;0">
                            <div class="shorthelp"><xsl:copy-of select="shorthelp/node()" /></div>
                        </xsl:if>
                        <xsl:choose>
                            <xsl:when test="count(./subsection)!=0">
                                <xsl:call-template name="subsection_tab_bar">
                                    <xsl:with-param name="active_subsec_id" select="$active_subsec_id"/>
                                </xsl:call-template>
<!-- to do...
                            <xsl:if test="./subsection[@id=$active_subsec_id]/context_help">
                                <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="subsection[@id=$active_subsec_id]/context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
                                <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
                            </xsl:if>
-->
                                <div class="ep_subsection_tabs">
                                    <xsl:apply-templates select="subsection">
                                        <xsl:with-param name="query" select="$query"/>
                                        <xsl:with-param name="target" select="$target"/>
                                        <xsl:with-param name="display_component" select="$display_component"/>
                                        <xsl:with-param name="active_subsec_id" select="$active_subsec_id"/>
                                        <xsl:with-param name="epc_input" select="$epc_input"/>
                                        <xsl:with-param name="process_status" select="$process_status"/>
                                    </xsl:apply-templates>
                                </div>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:apply-templates>
                                    <xsl:with-param name="query" select="$query"/>
                                    <xsl:with-param name="target" select="$target"/>
                                    <xsl:with-param name="display_component" select="$display_component"/>
                                    <xsl:with-param name="active_subsec_id" select="$active_subsec_id"/>
                                    <xsl:with-param name="epc_input" select="$epc_input"/>
                                    <xsl:with-param name="process_status" select="$process_status"/>
                                </xsl:apply-templates>
                            </xsl:otherwise>
                        </xsl:choose>
                    </div>
                </fieldset>
            </div>
        </xsl:if>
        <xsl:if test="$display_component=0">
            <div style="display: none">
                <xsl:apply-templates>
                    <xsl:with-param name="query" select="$query"/>
                    <xsl:with-param name="target" select="$target"/>
                    <xsl:with-param name="display_component" select="$display_component"/>
                    <xsl:with-param name="active_subsec_id" select="$active_subsec_id"/>
                    <xsl:with-param name="epc_input" select="$epc_input"/>
                </xsl:apply-templates>
            </div>
        </xsl:if>
        <xsl:comment>end section <xsl:value-of select="@id"/></xsl:comment>
    </xsl:template>

    <xsl:template match="subsection">
        <xsl:param name="query"/>
        <xsl:param name="target"/>
        <xsl:param name="active_subsec_id"/>
	<xsl:param name="epc_input" />

        <div id="subsection___c_{ancestor::component/@id}_s_{ancestor::section/@id}_su_{@id}">
            <xsl:attribute name="class">
                <xsl:choose>
                    <xsl:when test="./@id=$active_subsec_id">tab_active</xsl:when>
                    <xsl:otherwise>tab_inactive</xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <input type="hidden" name="subsection___c_{ancestor::component/@id}_s_{parent::section/@id}" value="{@id}" />
            <fieldset>
                <xsl:if test="string-length(shorthelp)&gt;0">
                    <div class="shorthelp">
                        <xsl:if test="count(shorthelp/following-sibling::*[not(name()='input' and @type='hidden')])&gt;0">
                            <xsl:attribute name="style">border-bottom: 1px solid #dfdfdf
                            </xsl:attribute>
                        </xsl:if>
                        <xsl:copy-of select="shorthelp/node()" />
                    </div>
                </xsl:if>
                <ol>
                    <xsl:apply-templates>
                        <xsl:with-param name="query" select="$query"/>
                        <xsl:with-param name="target" select="$target"/>
                        <xsl:with-param name="display_component" select="1"/>
                        <xsl:with-param name="active_subsec_id" select="$active_subsec_id"/>
                        <xsl:with-param name="epc_input" select="$epc_input"/>
                    </xsl:apply-templates>
                </ol>
            </fieldset>
        </div>
    </xsl:template>

    <xsl:template match="data_explorer">
        <xsl:param name="query" />
        <xsl:param name="target" />
        <xsl:param name="display_component" />
        <xsl:param name="epc_input" />

        <xsl:if test="$display_component=1">
            <xsl:variable name="data_tree" select="ep:get_data_tree()" />

            <script type="text/javascript">
<![CDATA[
function
ep_toggle_de_node(node)
    {
    var node_img = $(node).find(".ep_de_node > img")[0];
    var img_src  = is_msie_6() ? node_img.realSrc : node_img.src;
    var enclosure = $(node).find("ol:first");

    if ( img_src.match(/closed/ig) )
        { // open
        node_img.src = img_src.replace(/closed/ig, "open");
        enclosure.show().end();
        }
    else
        {
        node_img.src = img_src.replace(/open/ig, "closed");
        enclosure.hide().end();
        }
    }

function
ep_de_select_entity(entity)
    {
    $(entity).addClass("selected").removeClass("unselected");
    }

function
ep_de_unselect_entity(entity)
    {
    $(entity).addClass("unselected").removeClass("selected");
    }
]]>
            </script>
            <div id="ep_dataset_explorer" style="overflow:auto">
                <xsl:variable name="userdata">
                    <xsl:copy-of select="$data_tree/userdata/user/folder"/>
                </xsl:variable>
                <ol><xsl:apply-templates select="exsl:node-set($userdata)/*"/></ol>
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="data_explorer_node">
        <xsl:param name="uid" />
        <xsl:choose>
            <xsl:when test="count(./*[name()!='meta'])&gt;0"><!-- we have children -->
                <span class="ep_de_node" onclick="ep_toggle_de_node('#node_{$uid}')">
                    <xsl:choose>
                        <!-- TO DO -->
                        <xsl:when test="false() and name()='folder' and not(@is_current='1') and count(ancestor::folder)&gt;0"><img src="{$html_href}/static/images/tree12_closed.png" /></xsl:when>
                        <xsl:otherwise><img src="{$html_href}/static/images/tree12_open.png" /></xsl:otherwise>
                    </xsl:choose>
                </span>
            </xsl:when>
            <xsl:otherwise>
                <span class="ep_de_node" onclick="ep_toggle_de_node('#node_{$uid}')"><img src="{$html_href}/static/images/blank.gif" /></span>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:call-template name="data_explorer_item" />
        <xsl:call-template name="data_explorer_controls" />
    </xsl:template>

    <xsl:template name="data_explorer_item">
        <span class="ep_de_item">
            <xsl:choose>
                <xsl:when test="name()='folder'"><xsl:call-template name="data_explorer_folder" /></xsl:when>
                <xsl:when test="name()='dataset'"><xsl:call-template name="data_explorer_dataset" /></xsl:when>
                <xsl:when test="name()='action'"><xsl:call-template name="data_explorer_action" /></xsl:when>
            </xsl:choose>
        </span>
    </xsl:template>

    <xsl:template name="data_explorer_folder">
        <xsl:choose>
            <xsl:when test="count(ancestor::folder)=0"><img src="{$html_href}/static/images/folder_home.png" /></xsl:when>
            <xsl:otherwise><img src="{$html_href}/static/images/folder.png" /></xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="@name" />
    </xsl:template>

    <xsl:template name="data_explorer_dataset">
        <xsl:choose>
            <xsl:when test="action/meta[@name='upload_data_type']='exp::affy'"><img src="{$html_href}/static/images/affy_data.png" /></xsl:when>
            <xsl:when test="action/meta[@name='upload_data_type']='exp::arrayexpress'"><img src="{$html_href}/static/images/ae_data.png" /></xsl:when>
            <xsl:otherwise><img src="{$html_href}/static/images/data.png" /></xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="@dataset_name" />
    </xsl:template>

    <xsl:template name="data_explorer_action">
        <img src="{$html_href}/static/images/action.png" /><xsl:value-of select="@component_name" />
    </xsl:template>

    <xsl:template name="data_explorer_controls">
        <span class="ep_de_controls" style="">
            <xsl:choose>
                <xsl:when test="name()='folder'"><xsl:call-template name="data_explorer_folder_controls" /></xsl:when>
                <xsl:when test="name()='dataset'"><xsl:call-template name="data_explorer_dataset_controls" /></xsl:when>
                <xsl:when test="name()='action'"><xsl:call-template name="data_explorer_action_controls" /></xsl:when>
            </xsl:choose>
        </span>
    </xsl:template>

    <xsl:template name="data_explorer_folder_controls">
        <a href="javascript:new_folder({@id})"><img src="{$html_href}/static/images/folder_add.png" title="Add subfolder" /></a>
        <xsl:if test="count(ancestor::folder)&gt;0">
            <a href="javascript:delete_folder({@id})"><img src="{$html_href}/static/images/folder_delete.png" title="Delete folder" /></a>
            <input id="chk_folder_{@id}" name="chk_folder_{@id}" style="display: none" type="checkbox" />
        </xsl:if>
    </xsl:template>


    <xsl:template name="data_explorer_dataset_controls">
        <a href="{@data}" target="_blank"><img src="{$html_href}/static/images/data_view.png" title="View data"/></a>
        <a href="{@rows}" target="_blank"><img src="{$html_href}/static/images/data_annots.png" title="View row headers" /></a>
        <a href="{@cols}" target="_blank"><img src="{$html_href}/static/images/data_factors.png" title="View column headers"/></a>
        <a href="javascript:delete_dataset({@dataset_id})"><img src="{$html_href}/static/images/data_delete.png" title="Delete dataset" /></a>
        <input id="chk_dataset_{@dataset_id}" name="chk_dataset_{@dataset_id}" style="display: none" type="checkbox" />
    </xsl:template>


    <xsl:template name="data_explorer_action_controls">
        <a href="{$cgi_href}/ep_get_data.pl?dataset_id={@dst_dataset}" target="_blank"><img src="{$html_href}/static/images/data_view.png" title="View data" /></a>
        <a href="{$cgi_href}/display_action_meta.pl?action_id={@action_id}" target="_blank"><img src="{$html_href}/static/images/action_output_view.png" title="View action output" /></a>
        <!-- TO DO
            <a href="javascript:saveas_action({@action_id})"><img src="{$html_href}/static/images/data_save.png" /></a>
        -->
        <a href="javascript:delete_action({@action_id})"><img src="{$html_href}/static/images/data_delete.png" title="Delete action" /></a>
        <input id="chk_action_{@action_id}" name="chk_action_{@action_id}" style="display: none" type="checkbox" />
    </xsl:template>

    <xsl:template match="folder|dataset|action">
        <xsl:variable name="uid" select="generate-id(.)" />
        <li id="node_{$uid}">
            <div id="entity_{$uid}" class="unselected" onmouseover="ep_de_select_entity('#entity_{$uid}')" onmouseout="ep_de_unselect_entity('#entity_{$uid}')">
                <xsl:call-template name="data_explorer_node">
                    <xsl:with-param name="uid" select="$uid" />
                </xsl:call-template>
            </div>
<!-- TO DO
                <xsl:apply-templates select="*[name()='meta'][@label!=''][@type='xml/table']">
                </xsl:apply-templates>
-->
            <xsl:if test="count(child::node())&gt;0"><ol><xsl:apply-templates /></ol></xsl:if>
        </li>
    </xsl:template>

    <xsl:template match="dynamic_jscript">
        <xsl:param name="this_input"/>
        <xsl:element name="script">
            <xsl:attribute name="language">javascript</xsl:attribute>
            <xsl:value-of disable-output-escaping="yes" select="ep:dynamic_data(string(ancestor::component/@id), string(@call), string(@arg))"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="text">
        <div class="text">
            <xsl:copy-of select="node()" />
        </div>
    </xsl:template>
<!--
    <xsl:template match="input_group">
        <xsl:param name="query"/>
        <xsl:param name="target"/>
        <xsl:param name="display_component" select="1"/>
        <xsl:param name="epc_input"/>

    <tr>
      <xsl:if test="./context_help">
        <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
        <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
      </xsl:if>
      <td>
        <xsl:choose>
          <xsl:when test="$display_component=1"> 
            <span class="toolInputHelp" style="white-space:nowrap">
              <xsl:copy-of select="shorthelp"/>
            </span>
          </xsl:when>
        </xsl:choose>
      </td>
      <td align="left" width="100%">
        <table width="100%" border="0" cellpadding="2" cellspacing="0">
          <xsl:if test="@eltpos='vertical'">
            <xsl:for-each select="*">
              <tr>
                <td width="100%" align="left" valign="top">
                  <table width="100%" cellpadding="0" cellspacing="0" style="padding-left:5px">
                    <xsl:apply-templates select=".">
                      <xsl:with-param name="query" select="$query"/>
                      <xsl:with-param name="target" select="$target"/>
                      <xsl:with-param name="display_component" select="$display_component"/>
                      <xsl:with-param name="epc_input" select="$epc_input"/>
                    </xsl:apply-templates>
                  </table>
                </td>
              </tr>           
            </xsl:for-each>
          </xsl:if>
          <xsl:if test="not(@eltpos='vertical')">
            <tr>
              <xsl:for-each select="*">
                <td align="center" valign="center">
                  <table cellpadding="0" cellspacing="0" style="padding-left:5px">
                    <xsl:apply-templates select=".">
                      <xsl:with-param name="query" select="$query"/>
                      <xsl:with-param name="target" select="$target"/>
                      <xsl:with-param name="display_component" select="$display_component"/>
                      <xsl:with-param name="epc_input" select="$epc_input"/>
                    </xsl:apply-templates>
                  </table>
                </td>
              </xsl:for-each>
            </tr>
          </xsl:if>
        </table>
      </td>
    </tr>
  </xsl:template>
-->


    <xsl:template match="input">
        <xsl:param name="query" />
        <xsl:param name="target" />
        <xsl:param name="display_component" select="1" />
        <xsl:param name="process_status" />
        <xsl:param name="epc_input" />

        <xsl:variable name="this_input_name" select="@name" />
        <xsl:variable name="epc_input_value">
            <xsl:if test="$epc_input">
                <xsl:value-of select="$epc_input/output[@name=$this_input_name]/value" />
            </xsl:if>
        </xsl:variable>

        <xsl:variable name="input_name">
            <xsl:value-of select="@name" />___c_<xsl:value-of select="ancestor::component/@id" />_s_<xsl:value-of select="ancestor::section/@id" />
            <xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id" /></xsl:if>
        </xsl:variable>
        <xsl:variable name="value">
            <xsl:choose>
                <xsl:when test="string-length($epc_input_value)&gt;0">
                    <xsl:value-of select="$epc_input_value" />
                </xsl:when>
                <xsl:when test="$query//submit[@name=$input_name]">
                    <xsl:value-of select="$query//submit[@name=$input_name]/value" />
                </xsl:when>
                <xsl:when test="not($query//submit[@name=$input_name])">
                    <xsl:value-of select="@value" />
                </xsl:when>
            </xsl:choose>
        </xsl:variable>

<!--
        <xsl:if test="@required=1">
                  <td>
                    <xsl:if test="$query//submit[@name=$input_name]/@missing=1">
                      <xsl:attribute name="class">labelMissing</xsl:attribute>
                    </xsl:if>
                    *</td>
                </xsl:if>
                <xsl:if test="@required='' or @required='0'">
                  <td>&nbsp;</td>
                </xsl:if>
-->
        <xsl:choose>
            <xsl:when test="@type='hidden'">
                <input type="hidden" id="{@name}" name="{$input_name}" value="{$value}" />
            </xsl:when>
            <xsl:when test="$display_component=1">
                <li>
                    <xsl:if test="string-length(shorthelp)&gt;0">
                        <label for="{@name}"><xsl:copy-of select="shorthelp/node()" /><xsl:if test="@required=1">&#160;<em>*</em></xsl:if></label>
                    </xsl:if>
<!-- to do...
                <xsl:if test="./context_help">
                    <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
                    <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
                </xsl:if>
-->
<!-- to do...
            <xsl:if test="not(ancestor::input_group) and not(@type='proceed' or @type='submit')">
              <xsl:attribute name="width">70%</xsl:attribute>
            </xsl:if>
            <span class="toolInputHelp">
              <xsl:copy-of select="shorthelp"/>
            </span>
-->
                    <xsl:choose>
                        <xsl:when test="@type='proceed' or @type='submit'">
                        <!-- TO DO
                            <span class="toolInputHelp">
                                <xsl:if test="$process_status!=''">Try to correct the errors and proceed to:</xsl:if>
                            </span>
                        -->
                            <xsl:if test="not(ancestor::component/@id=20 or ancestor::component/@id=25)">
                                <xsl:call-template name="show_epc_target_links">
                                    <xsl:with-param name="epc_action" select="ancestor::component/action"/>
                                </xsl:call-template>
                            </xsl:if>

                            <xsl:if test="ancestor::component/@id=25">
                                <input type="hidden" name="prev_active_component_id" value="{$epc_input/@comp_id}"/>
                                    <xsl:call-template name="show_epc_target_links">
                                        <xsl:with-param name="epc_action" select="//component[@id=$epc_input/@comp_id]/action"/>
                                    </xsl:call-template>
                            </xsl:if>
                        </xsl:when>
                        <xsl:when test="@type='results'">
                            <input type="submit" onClick="ep_submit_component({ancestor::component/@id},'20:{ancestor::component/@id}:-1'); return false">
                                <xsl:attribute name="value">
                                    <xsl:choose>
                                        <xsl:when test="@label">
                                            <xsl:value-of select="@label"/>
                                        </xsl:when>
                                        <xsl:otherwise>Execute</xsl:otherwise>
                                    </xsl:choose>
                                </xsl:attribute>
                            </input>
                        </xsl:when>
<!-- to do... (do we have any <input type="cancel"> things?)
                <xsl:when test="@type='cancel'">
                    <a class="follow-assoc" href="javascript:cancel_component(20,{$epc_input/@comp_id});">
                        <b>&lt;&lt; Cancel</b>
                    </a>
                    <br/>
                </xsl:when>
-->
<!-- to do..
              <xsl:when test="@type='image'">
                <xsl:choose>
                  <xsl:when test="contains($value,'.png')">
                    <img id="{@name}" src="{$value}" name="{$input_name}" height="{@height}" width="{@width}" style="{@style}" title="{@title}"/>
                  </xsl:when>
                  <xsl:when test="contains($value,'.gif')">
                    <img id="{@name}" src="{$value}" name="{$input_name}" height="{@height}" width="{@width}" style="{@style}" title="{@title}"/>
                  </xsl:when>
                  <xsl:when test="contains($value,'.jpg')">
                    <img id="{@name}" src="{$value}" name="{$input_name}" height="{@height}" width="{@width}" style="{@style}" title="{@title}"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <div style="overflow:auto; width:{@width}; height:{@height}; z-index: 0">
                      <embed wmode="opaque" id="{@name}" src="{$value}" name="{$input_name}" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" height="{@height}" width="{@width}" style="z-index: 0"/>
                    </div>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
-->
<!--
              <xsl:when test="@type='choose_factors'">
                <select id="{@name}" style="width:250px">
                </select>
              </xsl:when>
-->
                        <xsl:otherwise>
                            <input id="{@name}" name="{$input_name}" size="{@size}">
                                <xsl:if test="string-length(@maxlength)&gt;0"><xsl:attribute name="maxlength"><xsl:value-of select="@maxlength" /></xsl:attribute></xsl:if>
                                <xsl:if test="@type!='text'"><xsl:attribute name="type"><xsl:value-of select="@type" /></xsl:attribute></xsl:if>
                                <xsl:attribute name="value"><xsl:if test="not(@required_for_action)"><xsl:value-of select="$value"/></xsl:if></xsl:attribute>
<!-- to do...
                        <xsl:if test="@onClick">
                            <xsl:attribute name="onClick">
                                <xsl:value-of select="@onClick"/>
                            </xsl:attribute>
                        </xsl:if>
-->
                            </input>
                        </xsl:otherwise>
                    </xsl:choose>

<!-- to do...
            <xsl:if test="@required_for_action">
              <script type="text/javascript">
                  required_for_action[required_for_action.length] = new Array ( "<xsl:value-of select="$input_name"/>", "<xsl:value-of select="@required_for_action"/>" );
              </script>
            </xsl:if>
-->
                </li>
            </xsl:when>
            <xsl:otherwise>
                <input id="{@name}" type="hidden" name="{$input_name}" value="{$value}" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="show_epc_target_links">
        <xsl:param name="epc_action"/>

        <xsl:variable name="target_owner_comp_id" select="ancestor::component/@id"/>
<!-- TO DO
        <xsl:if test="$user_level=0"><hr/><div class="ep_11px_bold">or proceed to:</div></xsl:if>
        <xsl:if test="$user_level=1"><hr/><div class="ep_11px_bold">or execute &amp; go to:</div></xsl:if>
-->
        <xsl:for-each select="$epc_action/target[not(@comp_id=20 or @comp_id=25 or @comp_id=-1)]">
            <xsl:variable name="target_comp_id" select="@comp_id"/>
            <xsl:variable name="target_id" select="@id"/>
            <xsl:variable name="target_value" select="."/>

            <xsl:if test="//component[@id=$target_comp_id]/@title">
                <div class="ep_11px_bold">
                    <a>
                        <xsl:if test="$user_level=0">
                            <xsl:attribute name="href"><xsl:value-of select="$cgi_href"/>/ep_ui.pl?render_component_ids=<xsl:value-of select="$target_comp_id"/></xsl:attribute>
                        </xsl:if>
                        <xsl:if test="$user_level>0">
                            <xsl:attribute name="href">javascript:ep_submit_component(<xsl:value-of select="$target_owner_comp_id"/>,'<xsl:value-of select="$target_comp_id"/>:<xsl:value-of select="ancestor::component/@id"/>:<xsl:value-of select="$target_id"/>');</xsl:attribute>
                        </xsl:if>
                        &#187;&#160;<xsl:value-of select="//component[@id=$target_comp_id]/@title"/><xsl:if test="./@label"> (<xsl:value-of select="./@label"/>)</xsl:if>
                    </a>
                </div>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

  <!-- ***************** embed  ******************* -->
  <xsl:template match="embed">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="1"/>
    <xsl:param name="process_status"/>
    <xsl:param name="epc_input"/>

    <xsl:variable name="embed_name" select="@name"/>
    <xsl:variable name="epc_input_src"><xsl:if test="$epc_input"><xsl:value-of select="$epc_input/output[@name=$embed_name]/value"/></xsl:if></xsl:variable>

    <xsl:variable name="input_name">
      <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>      
    </xsl:variable>
    <xsl:variable name="src"><xsl:choose><xsl:when test="string-length($epc_input_src)&gt;0"><xsl:value-of select="$epc_input_src"/></xsl:when><xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when><xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@src"/></xsl:when></xsl:choose></xsl:variable>

    <xsl:if test="$display_component=1">
      <tr>
        <xsl:if test="./context_help">
          <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
          <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
        </xsl:if>
        <td>
          <span class="toolInputHelp">
            <xsl:copy-of select="shorthelp"/>
          </span>
        </td>
        <td align="center" valign="middle">
          <!--          <div style="overflow:auto; height:530; width:100%">-->
            <xsl:choose>
              <xsl:when test="contains($src,'.png')">
                <img align="left" src="{$src}"/>
              </xsl:when>
              <xsl:otherwise>
                <embed wmode="opaque" src="{$src}" name="{$input_name}" id="svg_vis" type="{@type}" pluginspage="{@pluginspage}" width="{$epc_input/output[@name=concat($embed_name,'_width')]/value}" height="{$epc_input/output[@name=concat($embed_name,'_height')]/value}"/>
              </xsl:otherwise>
            </xsl:choose>
            <!--          </div>-->
        </td>
      </tr>
    </xsl:if>
  </xsl:template>

  <!-- ***************** applet  ******************* -->
  <xsl:template match="applet">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="1"/>
    <xsl:param name="process_status"/>
    <xsl:param name="epc_input"/>

    <xsl:variable name="applet_name" select="@name"/>

    <xsl:if test="$display_component=1">
      <tr>
        <xsl:if test="./context_help">
          <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
          <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
        </xsl:if>
        <td>
          <span class="toolInputHelp">
            <xsl:copy-of select="shorthelp"/>
          </span>
        </td>
        <td colspan="2" align="left" valign="middle">
          <xsl:copy-of select="."/>
        </td>
      </tr>
    </xsl:if>
  </xsl:template>


    <xsl:template match="select">
        <xsl:param name="query"/>
        <xsl:param name="target"/>
        <xsl:param name="display_component" select="1"/>

        <xsl:variable name="input_name">
            <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
        </xsl:variable>
        <xsl:variable name="value">
            <xsl:choose>
                <xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when>
                <xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@value"/></xsl:when>
            </xsl:choose>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="$display_component=1">
            <!-- TO DO
                <xsl:if test="./context_help">
                    <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); // event.stopPropagation()</xsl:attribute>
                    <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
                </xsl:if>
            -->
                <li>
            <!-- TO DO
            <xsl:if test="not(ancestor::input_group)">
              <xsl:attribute name="width">70%</xsl:attribute>
            </xsl:if>
            -->
            <!-- TO DO
            <span class="toolInputHelp">
              <xsl:copy-of select="shorthelp"/>
            </span>
            -->
            <!--
            <select onmouseover="event.cancelBubble=true;//event.stopPropagation()" style="width:250px" id="{@name}">
            -->
            <label for="{@name}"><xsl:copy-of select="shorthelp/node()" /></label>
            <select style="width: 250px" id="{@name}">
                <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
                <xsl:if test="@multiple">
                    <xsl:attribute name="multiple"/>
                    <xsl:attribute name="size"><xsl:value-of select="@size"/></xsl:attribute>
                </xsl:if>
                <xsl:for-each select="optgroup">
                    <optgroup label="{@label}">
                        <xsl:for-each select="option">
                            <option value="{@value}">
                                <xsl:if test="@value=$value">
                                    <xsl:attribute name="selected"/>
                                </xsl:if>
                                <xsl:value-of select="."/>
                            </option>
                        </xsl:for-each>
                    </optgroup>
                </xsl:for-each>
                <xsl:for-each select="option">
                    <option value="{@value}">
                        <xsl:if test="@value=$value">
                            <xsl:attribute name="selected"/>
                        </xsl:if>
                        <xsl:value-of select="."/>
                    </option>
                </xsl:for-each>
            </select>
                </li>
            </xsl:when>
            <xsl:otherwise>
                <input id="{@name}" type="hidden">
                    <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
                    <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
                </input>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <!-- ***************** checkbox ******************* -->
    <xsl:template match="checkbox">
        <xsl:param name="query"/>
        <xsl:param name="target"/>
        <xsl:param name="display_component" select="1"/>

        <xsl:variable name="input_name">
            <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
        </xsl:variable>
        <xsl:variable name="value">
            <xsl:choose>
                <xsl:when test="$query//submit[@name=$input_name]">
                    <xsl:value-of select="$query//submit[@name=$input_name]/value"/>
                </xsl:when>
                <xsl:when test="not($query//submit[@name=$input_name])">
                    <xsl:value-of select="@value"/>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="$display_component=1">
<!-- TO DO
          <xsl:if test="./context_help">
            <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
            <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
          </xsl:if>
          <td align="left">
            <xsl:if test="not(ancestor::input_group)">
              <xsl:attribute name="width">70%</xsl:attribute>
            </xsl:if>
-->
                <li>
                    <xsl:if test="string-length(shorthelp)&gt;0">
                        <label for="{@name}"><xsl:copy-of select="shorthelp/node()" /><xsl:if test="@required=1">&#160;<em>*</em></xsl:if></label>
                    </xsl:if>
                    <input type="checkbox" id="{@name}" name="{$input_name}">
                        <xsl:if test="@checked!=0">
                            <xsl:attribute name="checked"/>
                        </xsl:if>
                    </input>
                </li>
            </xsl:when>
            <xsl:otherwise>
                <input id="{@name}" type="hidden">
                    <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
                    <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
                </input>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

  <!-- ***************** textarea ******************* -->
  <xsl:template match="textarea">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="1"/>
    <xsl:param name="epc_input"/>

    <xsl:variable name="this_input_name" select="@name"/>
    <xsl:variable name="epc_input_value"><xsl:if test="$epc_input"><xsl:value-of select="$epc_input/output[@name=$this_input_name]/value"/></xsl:if></xsl:variable>

    <xsl:variable name="input_name">
      <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>      
    </xsl:variable>
    <xsl:variable name="value"><xsl:choose><xsl:when test="string-length($epc_input_value)&gt;0"><xsl:value-of select="$epc_input_value"/></xsl:when><xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when><xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@value"/></xsl:when></xsl:choose></xsl:variable>
    <xsl:choose>
      <xsl:when test="$display_component=1">
        <tr>
          <xsl:if test="./context_help">
            <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
            <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
          </xsl:if>
          <td>
            <span class="toolInputHelp">
              <xsl:copy-of select="shorthelp"/>
            </span>
            <xsl:if test="@required">
              <span>
                <xsl:if test="$query//submit[@name=$input_name]/@missing=1">
                  <xsl:attribute name="class">labelMissing</xsl:attribute>
                </xsl:if>
                *
              </span>
            </xsl:if>
          </td>
          <td align="right">
            <textarea style="width:250px" id="{@name}">
              <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
              <xsl:attribute name="rows"><xsl:value-of select="@rows"/></xsl:attribute>
              <xsl:attribute name="cols"><xsl:value-of select="@cols"/></xsl:attribute>
              <xsl:value-of select="$value"/>
            </textarea>
          </td>
        </tr>
      </xsl:when>
      <xsl:otherwise>
        <input id="{@name}" type="hidden">
          <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
          <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
        </input>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

    <!-- ***************** output  ******************* -->
    <xsl:template match="output">
        <xsl:param name="query"/>
        <xsl:param name="target"/>
        <xsl:param name="display_component" select="1"/>

        <xsl:variable name="output" select="ep:component_output(string(ancestor::component/@id))"/>
        <xsl:choose>
            <xsl:when test="$output!=''">
                <xsl:if test="ancestor::component/@id!=-1">
          <tr>
            <td colspan="2">
              <table border="0" cellspacing="0" cellpadding="2" width="100%">
                <xsl:for-each select="$output/epc_output/output">
                  <xsl:choose>
                    <xsl:when test="@type='hidden'">
                      <td>
                        <input id="{@name}">
                          <xsl:attribute name="type">
                            <xsl:value-of select="@type"/>
                          </xsl:attribute>
                          <xsl:attribute name="name">
                            <xsl:value-of select="@label"/>
                          </xsl:attribute>
                          <xsl:attribute name="value">
                            <xsl:value-of select="value"/>
                          </xsl:attribute>
                        </input>
                      </td><td></td>
                    </xsl:when>
                    <xsl:otherwise>
                      <tr>
                        <td width="35%">
                          <span class="outputLabel"><xsl:value-of select="@label"/></span>
                        </td>
                        <td align="right">
                          <span>
                            <xsl:if test="@matched=1"><xsl:attribute name="class">outputText</xsl:attribute></xsl:if>
                            <xsl:if test="@matched=0"><xsl:attribute name="class">outputTextNotMatched</xsl:attribute></xsl:if>
                            <xsl:if test="@error=1"><xsl:attribute name="class">outputTextError"</xsl:attribute></xsl:if>
                            
                            <xsl:value-of select="value"/>
                          </span>
                        </td>
                      </tr>                      
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </table>
            </td>
          </tr>                    
        </xsl:if>

        <!-- if the target = -1 (basic container), use the output text as URL -->
        <xsl:if test="ancestor::component/@id=-1">
          <xsl:value-of select="$output"  disable-output-escaping="yes"/>
          <!--
         <iframe id="container_frame" frameborder="0" height="0" width="0" onload="resize_container_frame()" src="{$output}">
          </iframe>
          -->
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- ***************** error  ******************* -->
  <xsl:template match="error">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="0"/>

    <xsl:variable name="errors"/>

    <!--
    <xsl:choose>
      <xsl:when test="$errors!=''">
        <xsl:variable name="errors" select="document($errors_uri)"/>
        <xsl:if test="count($errors/epc_error/error)>0">
          <tr>
            <td colspan="2">
              <table border="1" cellspacing="0" cellpadding="2" width="100%">
                <tr><th colspan="2">ERRORS</th></tr>
                <tr>
                  <th width="10%">Severity</th>
                  <th>Message</th>
                </tr>
                <xsl:for-each select="$errors/epc_error/error">
                  <tr>
                    <td align="center">
                      <span class="errorSeverity">
                        <xsl:choose>
                          <xsl:when test="@severity=1">
                            INFO
                          </xsl:when>
                          <xsl:when test="@severity=2">
                            WARNING
                          </xsl:when>
                          <xsl:when test="@severity=3">
                            ERROR
                          </xsl:when>
                        </xsl:choose>
                      </span>
                    </td>
                    <td align="left">
                      <span class="errorMessage">
                        <xsl:value-of select="text()"/>
                      </span>
                    </td>
                  </tr>
                </xsl:for-each>
                <xsl:if test="count($errors/epc_error/error[@severity=3])!=0">
                  <tr>
                    <td colspan="2" align="center">
                      <input type="button" value="Go back to try to correct the errors!" onClick="history.back();"/>
                    </td>
                  </tr>
                </xsl:if>
              </table><br/>
            </td>
          </tr>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>
        -->
  </xsl:template>

  <xsl:template match="toolbar">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component"/>
    <xsl:param name="epc_input"/>
    <tr>
      <td valign="top" align="right">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="95%"/>
            <xsl:for-each select="button">
              <td align="center" style="padding:2px;border:1px inset black">
                <img src="{@src}" title="{@title}" onmouseover="this.style.cursor='pointer'" onclick="{@onclick}" height="20" width="20"/><!-- height="{@height}" width="{@width}"/>-->
              </td>
            </xsl:for-each>
          </tr>
        </table>
      </td>
    </tr>
  </xsl:template>

  <!-- ***************** ep:dynamic_select ******************* -->
  <xsl:template match="dynamic_select">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="1"/>

    <xsl:variable name="input_name">
      <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>      
    </xsl:variable>
    <xsl:variable name="value"><xsl:choose><xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when><xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@value"/></xsl:when></xsl:choose></xsl:variable>
  
    <xsl:choose>
      <xsl:when test="$display_component=1">
        <xsl:variable name="selectdata" select="ep:dynamic_data(string(ancestor::component/@id), string(@call), string(@arg))"/>
        <tr>
          <xsl:if test="./context_help">
            <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
            <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
          </xsl:if>
          <td>
            <span class="toolInputHelp">
              <xsl:copy-of select="shorthelp"/>
            </span>
          </td>
          <td align="right">
            <select style="width:250px" id="{@name}">
              <xsl:attribute name="name">
                <xsl:value-of select="$input_name"/>
              </xsl:attribute>
              <xsl:if test="@onChange">
                <xsl:attribute name="onChange">
                  <xsl:value-of select="@onChange"/>
                </xsl:attribute>
              </xsl:if>
              <xsl:for-each select="$selectdata//item">
                <option>
                  <xsl:attribute name="value">
                    <xsl:value-of select="@key"/>
                  </xsl:attribute>
                  
                  <!-- test if $query contains some selections for this list, if so, ignore those from dynamic_data call -->
                  <xsl:choose>
                    <xsl:when test="string-length($value)!=0">
                      <xsl:if test="@key=$value">
                        <xsl:attribute name="selected"/>
                      </xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:if test="@selected=1">
                        <xsl:attribute name="selected"/>
                      </xsl:if>
                    </xsl:otherwise>
                  </xsl:choose>
                  <xsl:value-of select="text()"/>
                </option>
              </xsl:for-each>
            </select>
          </td>
        </tr>
      </xsl:when>
      <xsl:otherwise>
        <input id="{@name}" >
          <xsl:attribute name="type">hidden</xsl:attribute>
          <xsl:attribute name="name">
            <xsl:value-of select="$input_name"/>
          </xsl:attribute>
          <xsl:attribute name="value">
            <xsl:value-of select="$value"/>
          </xsl:attribute>
        </input>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- ***************** ep:dynamic_list  ******************* -->
  <xsl:template match="dynamic_list">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="1"/>
    <xsl:param name="epc_input"/>

    <xsl:variable name="list_name" select="./@name"/>
    <xsl:variable name="required" select="./dynamic_input/@required"/>
 
    <!-- need a test case for this $epc_input select -->
    <xsl:variable name="dyn_list_arg">
      <xsl:if test="$epc_input"><xsl:value-of select="$epc_input/output[@name=$list_name]/value"/></xsl:if>
    </xsl:variable>

    <xsl:variable name="listdata" select="ep:dynamic_data(string(ancestor::component/@id), string(@call), string($dyn_list_arg) )"/>
    <xsl:variable name="this_dynamic_input" select="./dynamic_input"/>

    <xsl:variable name="hidden_input_name">
      <xsl:value-of select="./@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
    </xsl:variable>
    
    <xsl:variable name="dynamic_input_name">
      <xsl:value-of select="./dynamic_input/@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
    </xsl:variable>

    <input id="{@name}" type="hidden">
      <xsl:attribute name="name"><xsl:value-of select="$hidden_input_name"/></xsl:attribute>
    </input>

    <input id="{dynamic_input/@name}" type="hidden">
      <xsl:attribute name="name"><xsl:value-of select="$dynamic_input_name"/></xsl:attribute>
    </input>

    <span class="toolInputHelp">
      <xsl:copy-of select="shorthelp"/>
    </span>

    <xsl:for-each select="$listdata//item">
      <xsl:choose>
        <xsl:when test="$display_component=1">
          <tr>
            <td>
              <span class="dynamic_list_head">
                <xsl:value-of select="@key"/>: <xsl:value-of select="text()"/>
              </span>
              <span>
                <xsl:if test="$required=1">
                  <xsl:if test="$query//submit[@name=$dynamic_input_name]/@missing=1">
                    <xsl:attribute name="class">labelMissing</xsl:attribute>
                  </xsl:if> *
                </xsl:if>
              </span>
              <table valign="top" border="1" width="100%" cellspacing="0">
                <xsl:call-template name="dynamic_input">
                  <xsl:with-param name="query" select="$query"/>
                  <xsl:with-param name="display_component" select="$display_component"/>
                  <xsl:with-param name="key" select="@key"/>
                  <xsl:with-param name="this_input" select="$this_dynamic_input"/>
                  <xsl:with-param name="epc_input" select="$epc_input"/>
                </xsl:call-template>
              </table>
            </td>
          </tr>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="dynamic_input">
            <xsl:with-param name="query" select="$query"/>
            <xsl:with-param name="display_component" select="$display_component"/>
            <xsl:with-param name="key" select="@key"/>
            <xsl:with-param name="this_input" select="$this_dynamic_input"/>
            <xsl:with-param name="epc_input" select="$epc_input"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>

  <!-- ************* ep:dynamic_input *************** -->
  <xsl:template match="dynamic_input">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="1"/>
    <xsl:param name="process_status"/>

    <xsl:variable name="input_name">
      <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
    </xsl:variable>
    
    <xsl:variable name="value"><xsl:choose><xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when><xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="ep:dynamic_data(string(ancestor::component/@id), string(@call))"/></xsl:when></xsl:choose></xsl:variable>
    <xsl:choose>
      <xsl:when test="@type='hidden'">
        <input id="{@name}" type="hidden" name="{$input_name}" value="{$value}"/>
      </xsl:when>
      <xsl:when test="$display_component=1">
        <tr>
          <xsl:if test="./context_help">
            <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
            <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
          </xsl:if>
          <td>
            <span class="toolInputHelp">
              <xsl:copy-of select="shorthelp"/>
            </span>
          </td>
          <td align="right">
            <input id="{@name}">
              <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
              <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
              <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
              <xsl:attribute name="size"><xsl:value-of select="@size"/></xsl:attribute>
              <xsl:attribute name="onClick">javascript:if (typeof <xsl:value-of select="$input_name"/>___onChange == "function") <xsl:value-of select="$input_name"/>___onChange(<xsl:value-of select="$value"/>)</xsl:attribute>
            </input>
          </td>
          <xsl:if test="@required=1">
            <td>
              <xsl:if test="$query//submit[@name=$input_name]/@missing=1">
                <xsl:attribute name="class">labelMissing</xsl:attribute>
              </xsl:if>
              *</td>
          </xsl:if>
          <xsl:if test="@required='' or @required='0'">
            <td>&#160;</td>
          </xsl:if>
        </tr>
      </xsl:when>
      <xsl:otherwise>
        <input id="{@name}" type="hidden">
          <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
          <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
        </input>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <!-- ************* ep:dynamic_input (named)  *************** -->
  <xsl:template name="dynamic_input">
    <xsl:param name="query"/>
    <xsl:param name="target"/>
    <xsl:param name="display_component" select="1"/>
    <xsl:param name="key"/>
    <xsl:param name="this_input"/>
    <xsl:param name="epc_input"/>
    
    <xsl:variable name="listdata" select="ep:dynamic_data(string($this_input/ancestor::component/@id), string($this_input/@call), string($key))"/>
    <xsl:variable name="input_type" select="$this_input/@type"/>

    <!-- input name now assumes one name for all items in the list, this should be changed so every item has its own name (to allow for checkboxes), which is read
         from the input xml file -->
    <!-- every item is now processed as well, which should be avoided when putting them as hidden inputs (only the first one with the same name has to be set) -->

     <xsl:variable name="input_name">
      <xsl:value-of select="$this_input/@name"/>___c_<xsl:value-of select="$this_input/ancestor::component/@id"/>_s_<xsl:value-of select="$this_input/ancestor::section/@id"/><xsl:if test="$this_input/ancestor::subsection">_su_<xsl:value-of select="$this_input/ancestor::subsection/@id"/></xsl:if>
    </xsl:variable>

    <xsl:variable name="epc_input_value"><xsl:if test="$epc_input"><xsl:value-of select="$epc_input/output[@name=$this_input/@name]/value"/></xsl:if></xsl:variable>

    <xsl:variable name="value"><xsl:choose><xsl:when test="string-length($epc_input_value)&gt;0"><xsl:value-of select="$epc_input_value"/></xsl:when><xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when><xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@value"/></xsl:when></xsl:choose></xsl:variable>

    <xsl:variable name="nr_of_items" select="count($listdata//item)"/>
    <xsl:for-each select="$listdata//item">
      <xsl:choose>
        <xsl:when test="$display_component=1">
          <xsl:if test="position()=1">
            <tr>
              <th>&#160;</th>

              <xsl:if test="./@col">
                <th>cols</th>
              </xsl:if>
              <xsl:if test="./@row">
                <th>rows</th>
              </xsl:if>

              <xsl:if test="./@del">
                <th>del</th>
              </xsl:if>

              <!--
              <xsl:for-each select="./@*">
                <xsl:if test="not(name()='name') and not(name()='key') and not(name()='href') and not(name()='col') and not(name()='row')">
                  <th><xsl:value-of select="name()"/></th>
                </xsl:if>
              </xsl:for-each>
              -->
            </tr>           
          </xsl:if>
          <tr valign="top">
            <td>
              <input id="{@name}">
                <xsl:attribute name="type"><xsl:value-of select="$input_type"/></xsl:attribute>
                <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
                <xsl:attribute name="value"><xsl:value-of select="@key"/></xsl:attribute>
                <xsl:attribute name="onClick">javascript:if (typeof <xsl:value-of select="$input_name"/>___onChange == "function") <xsl:value-of select="$input_name"/>___onChange('<xsl:value-of select="@key"/>')</xsl:attribute>

                <!-- test if $query contains some selections for this list, if so, ignore those from dynamic_data call -->
                <xsl:choose>
                  <xsl:when test="string-length($value)!=0">
                    <xsl:if test="contains(@key,$value)">
                      <xsl:attribute name="checked"/>
                    </xsl:if>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:if test="@selected=1 or $nr_of_items=1">
                      <xsl:attribute name="checked"/>
                    </xsl:if>
                  </xsl:otherwise>
                </xsl:choose>
              </input>

              <script type="text/javascript">
                Text['<xsl:value-of select="@key"/>']  = ['<xsl:value-of select="text()"/>', '<table width="300" cellpadding="0" cellspacing="0" border="0">'+
                <xsl:for-each select="./@*">
                  <xsl:if test="not(name()='name') and not(name()='key') and not(name()='href') and not(name()='col') and not(name()='row')">
                    '<tr>'+
                      '<td align="left"><xsl:value-of select="name()"/></td>' +
                      '<td align="right"><xsl:value-of select="."/></td>' +
                    '</tr>' +
                  </xsl:if>
                </xsl:for-each>
                '</table>'];
                //                Style['<xsl:value-of select="@key"/>'] = ["white","#000099","","","",,"black","#e8e8ff","","","",,,,2,"#000099",2,,,,,"",3,,,];
              </script>

              <!--
              <a target="_blank" onMouseOver="stm(Text['{@key}'],['white','#000099','','','',,'black','#e8e8ff','','','',,,,2,'#000099',2,,,,,'',3,,,])" onMouseOut="htm()">
                <xsl:if test="./@href">
                  <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
                </xsl:if>
                <xsl:copy-of disable-output-escaping="yes" select="text()"/>
              </a>
              -->
              <xsl:copy-of disable-output-escaping="yes" select="text()"/>
   
              <!-- for each selection execute the proper onClick selection javascript (as defined above)-->
              <script type="text/javascript">
                  onLoadHooks [ onLoadHooks.length ] = new Function (
                <xsl:choose>
                  <xsl:when test="string-length($value)!=0">
                    <xsl:if test="contains(@key,$value)">
                        "if (typeof <xsl:value-of select="$input_name"/>___onChange == 'function') <xsl:value-of select="$input_name"/>___onChange('<xsl:value-of select="@key"/>');"
                    </xsl:if>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:if test="@selected=1 or $nr_of_items=1">
                        "if (typeof <xsl:value-of select="$input_name"/>___onChange == 'function') <xsl:value-of select="$input_name"/>___onChange('<xsl:value-of select="@key"/>');"
                    </xsl:if>
                  </xsl:otherwise>
                </xsl:choose>
                )
              </script>
            </td>
              
            <xsl:if test="./@col">
              <td>
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                  <tr><td align="center"><xsl:value-of disable-output-escaping="yes" select="./@col"/></td></tr>
                </table>
              </td>
            </xsl:if>
            <xsl:if test="./@row">
              <td>
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                  <tr><td align="center"><xsl:value-of disable-output-escaping="yes" select="./@row"/></td></tr>
                </table>
              </td>
            </xsl:if>

            <xsl:if test="./@del">
              <td>
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                  <tr><td align="center"><xsl:value-of disable-output-escaping="yes" select="./@del"/></td></tr>
                </table>
              </td>
            </xsl:if>

            <!--
            <xsl:for-each select="./@*">
              <xsl:if test="not(name()='name') and not(name()='key') and not(name()='href') and not(name()='col') and not(name()='row')">
                <td>
                  <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <xsl:for-each select="str:tokenize(.,';')">
                      <xsl:variable name="items" select="str:tokenize(.,'|')"/>
                      <xsl:choose>
                        <xsl:when test="count($items)!=1">
                          <tr>
                            <xsl:for-each select="$items">
                              <xsl:if test="position()!=last()">
                                <td align="left">
                                  <xsl:value-of select="."/>
                                </td>
                              </xsl:if>
                              <xsl:if test="position()=last()">
                                <td align="right">
                                  <xsl:value-of select="."/>
                                </td>
                              </xsl:if>
                            </xsl:for-each>
                          </tr>
                        </xsl:when>
                        <xsl:otherwise>
                          <tr><td align="center"><xsl:value-of disable-output-escaping="yes" select="."/></td></tr>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:for-each>
                  </table>
                </td>
              </xsl:if>
            </xsl:for-each>
            -->
          </tr>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="string-length($value)!=0">
            <input id="{@name}">
              <xsl:attribute name="type">hidden</xsl:attribute>
              <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
              <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
            </input>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>


  <!-- ***************************** action *************************** -->
  <xsl:template match="action2">
    <script type="text/javascript">
        var targets = new Array();

        <xsl:for-each select="target">
          targets[<xsl:value-of select="@comp_id"/>] = '<xsl:copy-of select="."/>';
        </xsl:for-each>
    </script>
  </xsl:template>

    <xsl:template name="context_help">
        <xsl:param name="ctxt_helps"/>
<!-- to do:
        <xsl:for-each select="$ctxt_helps/para">
            <div id="ctxt_{@id}" style="display: none;"><xsl:copy-of select="text()"/></div>
        </xsl:for-each>
-->
    </xsl:template>

    <xsl:template match="user_preference">
        <xsl:param name="query" />
        <xsl:param name="target" />
        <xsl:param name="display_component" select="1" />

        <xsl:variable name="input_name">
            <xsl:value-of select="@name" />___c_<xsl:value-of select="ancestor::component/@id" />_s_<xsl:value-of select="ancestor::section/@id" /><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id" /></xsl:if>
        </xsl:variable>

        <xsl:variable name="user_configuration_value" select="ep:dynamic_data(string(ancestor::component/@id), string(@call), string(@arg))" />
        <xsl:variable name="input_value">
            <xsl:if test="$user_configuration_value"><xsl:value-of select="$user_configuration_value" /></xsl:if>
            <xsl:if test="not($user_configuration_value)"><xsl:value-of select="@default"/></xsl:if>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="$display_component=1"><li>
                <label for="{@name}"><xsl:copy-of select="shorthelp/node()" /></label>
<!-- to do
                <tr>
                    <xsl:if test="./context_help">
                        <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
                        <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
                    </xsl:if>
                    <td>
                        <span class="toolInputHelp"><xsl:copy-of select="shorthelp" /></span>
                    </td>
                    <td align="right">
-->
                    <select style="width:250px" id="{@name}" name="{$input_name}">
                        <xsl:for-each select="option">
                            <option value="{@value}">
                                <xsl:if test="@value=$input_value"><xsl:attribute name="selected"/></xsl:if>
                                <xsl:value-of select="."/>
                            </option>
                        </xsl:for-each>
                    </select>
                </li>
            </xsl:when>
            <xsl:otherwise>
                <input id="{@name}">
                    <xsl:attribute name="type">hidden</xsl:attribute>
                    <xsl:attribute name="name"><xsl:value-of select="$input_name" /></xsl:attribute>
                    <xsl:attribute name="value"><xsl:value-of select="$input_value" /></xsl:attribute>
                </input>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="show_outputs">
        <xsl:param name="query" />
        <xsl:param name="target" />
        <xsl:param name="epc_input" />

        <xsl:variable name="this_component_id" select="ancestor::component/@id" />

    <xsl:for-each select="$epc_input/output">
      <xsl:if test="not(@display='hidden')">
        <tr>
          <td>
            <b>
              <xsl:if test="@label"><xsl:value-of select="@label"/></xsl:if>
              <xsl:if test="not(@label)"><xsl:value-of select="@name"/></xsl:if>
            </b>
          </td>
          <td><xsl:value-of select="value"/></td>
        </tr>
      </xsl:if>
      <xsl:if test="@name='visualization'">
        <!--        <div style="overflow:auto; height:530; width:100%">-->
        <embed wmode="opaque" src="{value}" name="visualization" id="svg_vis" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" width="{$epc_input/output[@name='visualization_width']/value}" height="{$epc_input/output[@name='visualization_height']/value}"/>
          <!--        </div>-->
      </xsl:if>

      <input type="hidden" name="{@name}___c_{$this_component_id}_s_0" value="{value}"/>
    </xsl:for-each>

    <xsl:if test="count($epc_input/output[@display!='hidden'])=0">
      <tr><td>Component processed successfully.</td></tr>
    </xsl:if>
  </xsl:template>

    <xsl:template match="selectitems">
        <xsl:param name="query" />
        <xsl:param name="target" />
        <xsl:param name="display_component" select="1" />

        <xsl:variable name="input_name">
            <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
        </xsl:variable>
        <xsl:variable name="value">
            <xsl:choose>
                <xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when>
                <xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@value"/></xsl:when>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name="regexp_chk_name">
            <xsl:value-of select="@select"/>_regexp___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
        </xsl:variable>

        <xsl:variable name="negate_chk_name">
            <xsl:value-of select="@select"/>_negate___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="$display_component=1">
            <!-- TO DO
                <xsl:if test="./context_help">
                    <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
                    <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
                </xsl:if>
            -->
            <!--
            <xsl:if test="not(ancestor::input_group)">
              <xsl:attribute name="width">70%</xsl:attribute>
            </xsl:if>
            <span class="toolInputHelp">
              <xsl:copy-of select="shorthelp"/>
            </span>
            -->
            <table width="250" cellpadding="0" cellspacing="0">
              <tr>
                <td width="100%">
                  <textarea style="width:100%" name="{$input_name}" id="{$input_name}" rows="5" value=""/>
                </td>
                <td align="center">
                  <img title="Click to select items..." src="{$html_href}/static/images/gui_icons/selectgenes.png" onclick="ep_de_select_items('{$input_name}','{@select}')"/>
                  <br/>
                  <img title="Reset selection..." src="{$html_href}/static/images/gui_icons/resetgenes.png" onclick="{$input_name}.value=''"/>
                </td>
              </tr>
              <tr>
                <td colspan="2">
		  <input style="margin-left:0px" type="checkbox" name="{$regexp_chk_name}" value="1"/> use regexps/partial matching
                </td>
              </tr>
              <xsl:if test="@negate_available=1">
              <tr>
                <td colspan="2">
		  <input style="margin-left:0px" type="checkbox" name="{$negate_chk_name}" value="1"/> negate (invert) the selection
                </td>
              </tr>
              </xsl:if>
           </table>
            </xsl:when>
            <xsl:otherwise>
                <input id="{@name}" type="hidden">
                    <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
                    <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
                </input>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
  
    <xsl:template match="choosefactors">
        <xsl:param name="query"/>
        <xsl:param name="target"/>
        <xsl:param name="display_component" select="1"/>

        <xsl:variable name="input_name">
            <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
        </xsl:variable>
        <xsl:variable name="value">
            <xsl:choose>
                <xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when>
                <xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@value"/></xsl:when>
            </xsl:choose>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="$display_component=1">
<!-- TO DO
            <xsl:if test="./context_help">
                <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
                <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
            </xsl:if>
          <td align="left">
            <xsl:if test="not(ancestor::input_group)">
              <xsl:attribute name="width">70%</xsl:attribute>
            </xsl:if>
-->
                <li>
                    <label for="{$input_name}"><xsl:copy-of select="shorthelp/node()" /></label>
                    <select style="width:100%" name="{$input_name}" id="{@id}" size="5"/>
                    <img title="Define new factors..." src="{$html_href}/static/images/data_factors.png" onclick="define_new_factors('{@id}')"/>
                </li>
            </xsl:when>
            <xsl:otherwise>
              <input id="{@name}" type="hidden">
                <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
                <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
                </input>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="arrayexpress_experiments">
        <xsl:param name="query"/>
        <xsl:param name="target"/>
        <xsl:param name="display_component" select="1"/>

        <xsl:variable name="input_name">
            <xsl:value-of select="@name"/>___c_<xsl:value-of select="ancestor::component/@id"/>_s_<xsl:value-of select="ancestor::section/@id"/><xsl:if test="ancestor::subsection">_su_<xsl:value-of select="ancestor::subsection/@id"/></xsl:if>
        </xsl:variable>
        <xsl:variable name="value">
            <xsl:choose>
                <xsl:when test="$query//submit[@name=$input_name]"><xsl:value-of select="$query//submit[@name=$input_name]/value"/></xsl:when>
                <xsl:when test="not($query//submit[@name=$input_name])"><xsl:value-of select="@value"/></xsl:when>
            </xsl:choose>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="$display_component=1">
                <table width="100%" cellpadding="0" cellspacing="0">
                    <tr>
<!--
          <xsl:if test="./context_help">
            <xsl:attribute name="onMouseOver">setCtxtHelp ( "ctxt_<xsl:value-of select="context_help/@id"/>"); //event.stopPropagation()</xsl:attribute>
            <xsl:attribute name="onMouseOut">htm()</xsl:attribute>
          </xsl:if>
-->
                        <td align="left">
            <!-- 
                 <xsl:variable name="ae" select="ep:get_arrayexpress_experiments()"/>
                 <xsl:apply-templates select="$ae/experiments"/>
            -->
            <script type="text/javascript">//<![CDATA[
function ci(vg,Pf,yh) {
  this.type=vg;
  this.version=Pf;
  this.os=yh;
}

var m = new ci(0,0,null);
var Eb = navigator.userAgent.toLowerCase();
if ( Eb.indexOf ("msie") != -1 && document.all ) {
  m.type=1;
  if ( Eb.indexOf("msie 5") ) m.version=5;
} else if ( Eb.indexOf("safari") != -1 ) {
  m.type=3;
  if ( Eb.indexOf ("safari/125") !=-1 ) m.version=1;
} else if ( Eb.indexOf ("mozilla") != -1 ) {
  m.type=2;
} if ( Eb.indexOf ( "x11;" ) !=-1 ) {
  m.os=1;
}

function Xd() {};

Xd.create = function () {
  if ( m.type==1 ) {
    var Ud = m.version == 5 ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    return new ActiveXObject(Ud);
  } else {
    return new XMLHttpRequest();
  }
}

function Y ( Vc ) {
  if ( m.type == 1 ) {
    this.stylesheet = Vc;
  } else if ( m.type != 3 ) {
    this.processor=new XSLTProcessor();
    this.processor.importStylesheet(Vc);
  }
}

Y.cache_=new Object();

Y.create=function(Vc) {
  return new Y(Vc);
}
 
Y.getCached=function(lb) {
  return Y.cache_[lb];
}

Y.cache = function (lb, Nf) {
  Y.cache_[lb]=Nf;
}

Y.prototype.transformToHTML=function(qc,vb,params) {
  if ( this.stylesheet ) {
    for ( param in params ) {
        // hackish... :)
      var p = this.stylesheet.selectSingleNode ( '/xsl:stylesheet/xsl:param[@name="' + param + '"]' );
      p.text = params[param];
    }

    vb.innerHTML=qc.transformNode(this.stylesheet);
  } else {
    for ( param in params ) {
      this.processor.setParameter ( null, param, params[param] );
    }
    var Uh=this.processor.transformToFragment(qc,window.document);
    vb.innerHTML="";
    vb.appendChild(Uh);
  }
}

// kc - stylesheet URL
// qc - xml to transform
// vb - where in document to place the results
// Nc - function to call after transform
// params - array of parameters
Y.asynchronousTransform=function(qc,vb,kc,Nc,params) {
  if(m.type==3) return;

  var cc=Y.getCached(kc);

  if (cc) {
    cc.transformToHTML(qc,vb,params);
    if(Nc) Nc();
    return;
  }

  var sa = Xd.create();
  sa.open ( "GET", kc, true );

  sa.onreadystatechange = function () {
    if ( sa.readyState==4 ) {
      try {
	var Db = sa.responseXML;
	var cc = Y.create ( Db );
	Y.cache ( kc, cc );
	cc.transformToHTML ( qc, vb, params );
	if(Nc) Nc();
      } catch(b) {}
    }
  };

  sa.send(null);
}

            function transform_arrayexpress_experiments ( aediv, params ) {
              Y.asynchronousTransform ( aediv.xml, aediv, html_href + '/tmp/ae_experiments.xsl?' + Date(), null, params )
            }

            function load_arrayexpress_experiments ( from, to ) {
	      var organism;
	      var array;
	      var keyword;

       	      organism_filter = document.getElementById ( "ae_organism_filter" );
	      if ( organism_filter ) organism = organism_filter[organism_filter.selectedIndex].value;

	      
   	      array_filter = document.getElementById ( "ae_array_filter" );
	      if ( array_filter ) array = array_filter [ array_filter.selectedIndex ].value;

	      keyword_filter = document.getElementById ( "ae_keyword_filter" );
	      if ( keyword_filter ) keyword = keyword_filter.value;

              var xmlhttp = Xd.create();

              if ( xmlhttp ) {
                var aediv = document.getElementById ( "arrayexpress_experiments" );

		var params = {};
		
		if ( from     ) params.from = from;;
		if ( to       ) params.to = to;
		if ( organism ) params.organism = organism;;
		if ( array    ) params.array = array;
		if ( keyword  ) params.keyword = keyword;

                var query = "";
		for ( p in params ) { query += p + "=" + params[p] + ";" }
		
                xmlhttp.open ( "GET", cgi_href + "/ep_get_arrayexpress_experiments.pl?" + query );
                xmlhttp.onreadystatechange = function () {
                  if ( xmlhttp.readyState == 4 ) {
                    aediv.xml = xmlhttp.responseXML;
                    transform_arrayexpress_experiments ( aediv, params );
		    document.body.style.cursor = "default";
                  }
		}
		document.body.style.cursor = "wait";
                xmlhttp.send(null)
              }
            }
            //]]></script>

	  <div id="arrayexpress_experiments"><span style="color: red; text-decoration: blink; font-family: 'Lucida Grande', Verdana, Arial; font-size: 11px">Loading experiments...</span></div>
            <script type="text/javascript">load_arrayexpress_experiments( 1, 40 )</script>
            <input type="hidden" id="arrayexpress_badg_input" name="{$input_name}" value=""/>
          </td>
        </tr></table>
      </xsl:when>
      <xsl:otherwise>
        <input id="{@name}" type="hidden">
          <xsl:attribute name="name"><xsl:value-of select="$input_name"/></xsl:attribute>
          <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
        </input>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="*"></xsl:template>
</xsl:stylesheet>

